﻿#pragma once
#include <QTreeView>
#include <QScopedPointer>
#include <QPointer>

#include <QStandardItemModel>
#include <QStandardItem>

class ObjectTreeView : public QTreeView {
    Q_OBJECT
    struct ObjectTreeViewData;
    QScopedPointer<ObjectTreeViewData> d;
public:
    ~ObjectTreeView();
    explicit ObjectTreeView(QWidget *parent = nullptr);
    void setRootObject(QPointer<QObject> object);
    QObject *currentObject() const;

signals:
    void currentObjectChanged(QObject *object);

protected:
    QPointer<QStandardItemModel> model();
    void currentChanged(const QModelIndex &current, const QModelIndex &previous) override;

private:
    QStandardItem *addItem(QPointer<QObject> object, QStandardItem *parent, bool isRoot = false);
};
